let mongoose = require("mongoose");
mongoose.connect("mongodb://localhost:27017/newQY", {
    useNewUrlParser: true,
    useUnifiedTopology: true
}).then(() => {
    console.log("消费-集合连接成功！");
}).catch(() => {
    console.log("消费 - 集合连接失败！");
})
let schema = mongoose.Schema;
let expenseList = new schema({
    user: {
        required: true,
        type: String
    },
    // 当前消费总金额
    total: {
        type: Number,
        required: true,
        default: 0
    },
    item: [{
        yearDate: {
            type: String,
            require: true
        },
        yearTotal: {
            type: Number,
            required: true,
            default: 0
        },
        yearDetails: [{
            monDate: {
                type: String,
                require: true
            },
            monTotal: {
                type: Number,
                required: true,
                default: 0
            },
            monDetails: [{
                dayDate: {
                    type: String,
                    require: true
                },
                dayTotal: {
                    type: Number,
                    required: true,
                    default: 0
                },
                dayDetails: [{
                    //创建的时间
                    createTime: {
                        type: String,
                        required: true
                    },
                    //消费金额
                    money: {
                        type: Number,
                        required: true
                    },
                    // 消费的类型
                    type: {
                        type: String,
                        required: true
                    },
                    desc: {
                        type: String,
                        // required: true,
                        // default:""
                    }
                }]
            }]
        }]
    }]
})
let expense = mongoose.model("expenselist", expenseList);
module.exports = {
    expense
}